package network

import (
	"leaf/core/msg"
	"net"
	"time"
)

const (
	Default_LenMsgLen    = 4
	Default_MinMsgLen    = 9
	Default_MaxMsgLen    = 1024 * 10
	Default_LittleEndian = false
)

var DefaultMsgParser = &MsgParser{
	lenMsgLen:    Default_LenMsgLen,
	minMsgLen:    Default_MinMsgLen,
	maxMsgLen:    Default_MaxMsgLen,
	littleEndian: Default_LittleEndian,
}

var (
	CONNECT_INTERVAL = 100 * time.Millisecond

	CONN_STATUS_NONE    int32 = 0
	CONN_STATUS_CONNECT int32 = 1
	CONN_STATUS_WOKEING int32 = 2
)

var (
	CONN_TYPE_NONE    int32 = 0
	CONN_TYPE_ACCEPT  int32 = 1
	CONN_TYPE_CONNECT int32 = 2
)

type Agent interface {
	Process(head *msg.MessageHead, msgBytes []byte)
	OnClose()
}

type Conn interface {
	ReadMsg() ([]byte, error)
	WriteMsg(args ...[]byte) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Start() bool
	Close()
	Destroy()
	GetAgent() Agent
}
